package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.SysPictureEntDTO;
import com.macro.mall.model.BasicKeyImg;
import com.macro.mall.service.SysPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/sys/picture")
public class SysPictureController {
    @Autowired
    private SysPictureService sysPictureService;

    @RequestMapping("/list")
    public CommonResult list(@RequestBody SysPictureEntDTO sysPictureEntDTO) {
        return sysPictureService.list(sysPictureEntDTO);
    }

    /***
     * 新增 图片配置
     * @return
     */
    @PostMapping("add")
    public CommonResult add(BasicKeyImg img, MultipartFile imgFile) {
        img.setId(0L);
        return sysPictureService.edit(img, imgFile);
    }

    /***
     * 修改 图片配置
     */
    @PostMapping("/modify")
    public CommonResult modify(BasicKeyImg img, MultipartFile imgFile) {
        return sysPictureService.edit(img, imgFile);
    }

    /***
     * 删除 图片配置
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public CommonResult delete(@PathVariable(value = "id") Long id) {
        return sysPictureService.delete(id);
    }


    @PostMapping("/setStatus")
    public CommonResult setOn(@RequestBody SysPictureEntDTO sysPictureEntDTO) {
        BasicKeyImg img = new BasicKeyImg();
        img.setId(sysPictureEntDTO.getId());
        img.setStatus(sysPictureEntDTO.getStatus());
        return sysPictureService.edit(img, null);
    }


    @RequestMapping("/get")
    public CommonResult get(@RequestBody SysPictureEntDTO sysPictureEntDTO) {
        return null;
    }


    @RequestMapping("/setOff")
    public CommonResult setOff(@RequestBody SysPictureEntDTO sysPictureEntDTO) {
        return null;
    }
}
